package com.jyh.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/12/27 10:03
 */
@Configuration
public class EsConfig {
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        //String hostname, int port, String scheme
        HttpHost httpHost=new HttpHost("localhost",9200,"http");
        //HttpHost... hosts: es可能是一个集群。
        RestClientBuilder restClientBuilder= RestClient.builder(httpHost);
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
        return restHighLevelClient;
    }
}
